package com.jse.util.concurrent.old.synchronization.volatile1;

import org.junit.Test;

/**
 * 旧版本java实现同步：有synchronized和volatile两种，都是基于关键字java本身的
 * 
 * 参考：http://www.ibm.com/developerworks/cn/java/j-jtp06197.html
 * 
 * http://blog.csdn.net/ns_code/article/details/17348313 happen-before原则
 * 
 * @author zenghua233
 *
 */
public class VolatileTest {
	public VolatileFeaturesExample obj = new VolatileFeaturesExample();

	@Test
	public void testVolatile() {
		TaskA task;
		for (int i = 0; i < 100; i++) {
			task = new TaskA("TaskA" + i);
			task.start();
		}
	}

	class TaskA extends Thread {
		String taskName;

		public TaskA(String name) {
			this.taskName = name;
		}

		@Override
		public void run() {
//			obj.set(1L);
			obj.getAndIncrement();
			System.out.println(obj.get());
		}
	}
}
